Skip to content

Adding Kernel PCovC Code #254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 28 commits into from
Jun 28, 2025
Merged

Adding Kernel PCovC Code #254

merged 28 commits into from
Jun 28, 2025

Conversation

rvasav26
Copy link
Collaborator

@rvasav26 rvasav26 commented Jun 8, 2025

Adding Kernel PCovC code, examples, and testing suite. Adding a KPCov base class that both Kernel PCovR and Kernel PCovC inherit from.

Contributor (creator of PR) checklist

  • Tests updated (for new features and bugfixes)?
  • Documentation updated (for new features)?
  • Issue referenced (for PRs that solve an issue)?

For Reviewer

  • CHANGELOG updated if important change?

📚 Documentation preview 📚: https://scikit-matter--254.org.readthedocs.build/en/254/

@rvasav26 rvasav26 force-pushed the adding-kpcovc-new branch from 82aa115 to 9e4e3d8 Compare June 17, 2025 19:20
@rvasav26 rvasav26 marked this pull request as ready for review June 19, 2025 17:16
Copy link
Collaborator

@rosecers rosecers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good. In general, I like to keep PR's single purpose (@ceriottm will tell you I can be quite vigilant). The changes to PCovC seem small enough, however. I'd just go through and finalize a couple reformatting things then we should be good.

Number of components to keep.
if n_components is not set all components are kept::
n_components == n_samples
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inline

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could, but if we do, we would lose this appearance (and docs build formatting fails):
img

Comment on lines 71 to 79
classifier: `estimator object` or `precomputed`, default=None
classifier for computing :math:`{\mathbf{Z}}`. The classifier should be one of
`sklearn.linear_model.LogisticRegression`, `sklearn.linear_model.LogisticRegressionCV`,
`sklearn.svm.LinearSVC`, `sklearn.discriminant_analysis.LinearDiscriminantAnalysis`,
`sklearn.linear_model.RidgeClassifier`, `sklearn.linear_model.RidgeClassifierCV`,
`sklearn.linear_model.SGDClassifier`, or `Perceptron`.
If a pre-fitted classifier is provided, it is used to compute :math:`{\mathbf{Z}}`.
If None, ``sklearn.linear_model.LogisticRegression()``
is used as the classifier.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is formatted weird in the docs, is there any other way we can do this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed this to be a list for both KPCovC and PCovC (they have the similar docs here).

@@ -76,8 +67,8 @@ class KernelPCovR(_BasePCA, LinearModel):
If `precomputed`, we assume that the `y` passed to the `fit` function
is the regressed form of the targets :math:`{\mathbf{\hat{Y}}}`.

kernel : "linear" | "poly" | "rbf" | "sigmoid" | "cosine" | "precomputed"
Kernel. Default="linear".
kernel : {'linear', 'poly', 'rbf', 'sigmoid', 'cosine', 'precomputed'} or callable, default='linear'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the formatting change here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be fine but please use double quotes for strings.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the vertical bars to match how we format the rest of the parameters that contain a list of options. Added double quotes

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I LOVE this example.

Copy link
Collaborator

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice. I have some minor styling comments but should be easy to implement.

"""
return super().inverse_transform(T)

def decision_function(self, X=None, T=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems not tested very well. You think you can extend the tests to cover the points codecov is complaining?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point -- we are adding some more tests to this in our next update for multi-output PCovC/KPCovC. For now, I think I will leave it

Copy link
Collaborator

@PicoCentauri PicoCentauri Jun 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay should this be doner in another PR? If yes just open an issue to keep track of the TODOs please.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rvasav26 I think we should try to add these tests in this PR. These look easy to test.

@@ -76,8 +67,8 @@ class KernelPCovR(_BasePCA, LinearModel):
If `precomputed`, we assume that the `y` passed to the `fit` function
is the regressed form of the targets :math:`{\mathbf{\hat{Y}}}`.

kernel : "linear" | "poly" | "rbf" | "sigmoid" | "cosine" | "precomputed"
Kernel. Default="linear".
kernel : {'linear', 'poly', 'rbf', 'sigmoid', 'cosine', 'precomputed'} or callable, default='linear'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be fine but please use double quotes for strings.

Copy link
Collaborator

@PicoCentauri PicoCentauri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. I am happy.

"kernel_params": {"kernel": "rbf", "gamma": 12},
"title": "Logistic Regression",
},
RidgeClassifier(random_state=random_state): {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also use RidgeClassifierCV here!

Copy link
Collaborator

@cajchristian cajchristian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very happy - just left a few comments, and will approve once tests for the kpcovc decision function have been written.

@rvasav26 rvasav26 force-pushed the adding-kpcovc-new branch from 714ea50 to a1a316a Compare June 26, 2025 21:14
@PicoCentauri PicoCentauri merged commit 004287c into main Jun 28, 2025
12 checks passed
@PicoCentauri PicoCentauri deleted the adding-kpcovc-new branch June 28, 2025 08:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants